package app.musicPlayer.domain;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.CheckBox;
import app.utils.Utiles;

public class Ajustes extends PreferenceActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.opciones);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.menuajustes, menu);
	    return true;
	}
	   
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.menuinici:
				volvermenuprinc();
		        return true;
		    default:
		        return super.onOptionsItemSelected(item);
		}
	}
	
	private void volvermenuprinc() {
		AlertDialog alertDialog = new AlertDialog.Builder(Ajustes.this).create();
    	alertDialog.setMessage("Se han guardado los cambios");
 	    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
 	    	public void onClick(DialogInterface dialog, int which) {
 	    		returnToMainView(null);
 	    	} 
    	});
     	alertDialog.show();
	}
	
	private void returnToMainView(Bundle b) {
    	Intent intent = new Intent(Ajustes.this, SocialMusicPlayerActivity.class);
    	if(b != null) {
    		intent.putExtras(b);
    	}
    	finish();
    	startActivity(intent);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch(keyCode){
			case KeyEvent.KEYCODE_BACK:
				volvermenuprinc();
				return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
	
	

